<template>
	<div>
		<div class="mainBox">
			<el-form :inline="true" :model="ruleForm" :rules="rules" ref="ruleForm" label-width="110px" class="formBox">
				<el-row :gutter="20">
					<el-col :span="8">
						<el-form-item label="抵扣账号" prop="user_count">
							<el-input placeholder="请输入抵扣账号" v-model="ruleForm.user_count"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="抵扣单号" prop="consumption_number">
							<el-input placeholder="请输入抵扣单号" v-model="ruleForm.consumption_number"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="所属门店" prop="subordinate_stores">
							<el-input placeholder="" v-model="ruleForm.subordinate_stores" :disabled="disable"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="抵扣金额" prop="consumption_amount">
							<el-input placeholder="请输入抵扣金额" v-model="ruleForm.consumption_amount" type="number" @blur="reduceMoney"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="抵扣积分" prop="consumption_amount">
							<el-input placeholder="请输入抵扣积分" v-model="ruleForm.deductionIntegral" disabled type="number"></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="8">
						<el-form-item label="用户密码" prop="password">
							<el-input placeholder="请输入用户密码" v-model="ruleForm.password" type="password"></el-input>
						</el-form-item>
					</el-col>

				</el-row>
				<div style="text-align:right;margin-right:70px;">
					<el-form-item class="secondRow_formItem" style="margin-left:35px;">
						<el-button type="primary" @click="submitForm('ruleForm')" v-loading="submitLoading">确定</el-button>
					</el-form-item>
				</div>
			</el-form>
		</div>
	</div>
</template>

<script>
import { integralEnterLogOutAdd } from "@/api/user";
export default {
  data() {
    return {
      disable: true,
      submitLoading: false,
      ruleForm: {
        user_count: "",
        consumption_number: "",
        subordinate_stores: JSON.parse(this.$store.state.user.getStore)
          .storeName,
        consumption_amount: "",
        password: "",
        deductionIntegral: ""
      },
      rules: {
        user_count: [
          {
            required: true,
            message: "请输入抵扣账号",
            trigger: "blur"
          }
        ],
        consumption_number: [
          {
            required: true,
            message: "请输入抵扣单号",
            trigger: "blur"
          }
        ],
        consumption_amount: [
          {
            required: true,
            message: "请输入抵扣金额",
            trigger: "blur"
          }
        ],
        password: [
          {
            required: true,
            message: "请输入用户密码",
            trigger: "blur"
          }
        ]
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.submitLoading = true;
          let data = {
            memberId: this.ruleForm.user_count,
            deductionNumber: this.ruleForm.consumption_number,
            deductionMoney: this.ruleForm.consumption_amount,
            deductionIntegral: this.ruleForm.deductionIntegral,
            password: this.ruleForm.password
          };
          integralEnterLogOutAdd(data).then(res => {
            if (res.code == 200) {
              this.$message.success("抵扣成功");
              this.submitLoading = false;
              this.ruleForm.user_count = "";
              this.ruleForm.consumption_amount = "";
              this.ruleForm.deductionIntegral = "";
              this.ruleForm.password = "";
              this.ruleForm.consumption_number = "";
            } else {
              this.$message.error(res.msg);
              this.submitLoading = false;
            }
          });
        } else {
          return false;
        }
      });
	},
	reduceMoney(){

		this.ruleForm.deductionIntegral=this.ruleForm.consumption_amount*10
	}
  }
};
</script>

<style>
.formBox {
  margin-top: 20px;
}
</style>
